package org.pliers;

import com.alibaba.otter.canal.protocol.CanalEntry.*;
import org.pliers.canal.annotation.CanalSubscriber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CanalHandler {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @CanalSubscriber(eventType = EventType.INSERT,tableName = "member_info",schemaName = "nimble_center_member")
    public void handle(RowChange rowChange){
        for (RowData rowData : rowChange.getRowDatasList()) {
            logger.info("-------&gt; before");
            printColumn(rowData.getBeforeColumnsList());
            logger.info("-------&gt; after");
            printColumn(rowData.getAfterColumnsList());
        }
    }

    private void printColumn(List<Column> columns) {
        for (Column column : columns) {
            logger.info(column.getName() + " : " + column.getValue() + "    update=" + column.getUpdated());
        }
    }
}
